home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE08 / FILES / NETLOCK.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1996-02-19  |  2.2 KB  |  79 lines

  1. unit NetLock;
  2.  
  3. interface
  4.  
  5. uses
  6.   WinTypes, WinProcs;
  7.  
  8. { Core routine that mimics Win32 parameter set }
  9. {$ifndef Win32}
  10. function LockFile(Handle: Integer; FileOffsetLow, FileOffsetHigh,
  11.                   LockBytesLow, LockBytesHigh: Integer): Bool;
  12. {$endif}
  13. { Handle based routine that un/locks a given number of bytes }
  14. function LockFileArea(Handle: Integer; FileOffset, LockBytes: Longint;
  15.                       Unlock: Boolean): Bool;
  16. { File variable based routine that un/locks a given number of records }
  17. function LockFileVarArea(var FileVar; RecordNumber, NumRecords: Longint;
  18.                          Unlock: Boolean): Bool;
  19. { File variable based routine that un/locks one record }
  20. function LockFileVar(var FileVar; RecordNumber: Longint;
  21.                      Unlock: Boolean): Bool;
  22.  
  23. implementation
  24.  
  25. uses
  26.   SysUtils;
  27.  
  28. const
  29.   LockSpecifier: Byte = 0;
  30.  
  31. {$ifndef Win32}
  32. { Core routine that mimics Win32 parameter set }
  33. function LockFile(Handle: Integer; FileOffsetLow, FileOffsetHigh,
  34.   LockBytesLow, LockBytesHigh: Integer): Bool; assembler;
  35. asm
  36.   mov ah, $5C
  37.   mov al, LockSpecifier
  38.   mov bx, Handle
  39.   mov cx, FileOffsetHigh
  40.   mov dx, FileOffsetLow
  41.   mov si, LockBytesHigh
  42.   mov di, LockBytesLow
  43.   int $21
  44.   jnc @1
  45.   xor ax, ax
  46.   jmp @2
  47.  @1:
  48.   mov ax, 1
  49.  @2:
  50. end;
  51. {$endif}
  52.  
  53. { Handle based routine that un/locks a given number of bytes }
  54. function LockFileArea(Handle: Integer; FileOffset, LockBytes: Longint;
  55.                       Unlock: Boolean): Bool;
  56. begin
  57.   LockSpecifier := Byte(Unlock);
  58.   Result := LockFile(Handle, LoWord(FileOffset),
  59.     HiWord(FileOffset), LoWord(LockBytes), HiWord(LockBytes));
  60. end;
  61.  
  62. { File variable based routine that un/locks a given number of records }
  63. function LockFileVarArea(var FileVar; RecordNumber, NumRecords: Longint;
  64.                          Unlock: Boolean): Bool;
  65. begin
  66.   with TFileRec(FileVar) do
  67.     Result := LockFileArea(Handle, Recordnumber * RecSize,
  68.                            NumRecords * RecSize, Unlock);
  69. end;
  70.  
  71. { File variable based routine that un/locks one record }
  72. function LockFileVar(var FileVar; RecordNumber: Longint;
  73.                         Unlock: Boolean): Bool;
  74. begin
  75.   Result := LockFileVarArea(FileVar, RecordNumber, 1, Unlock);
  76. end;
  77.  
  78. end.
  79.